﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Vici.Mvc;
using Ss.Model;
using SSOtest.ServiceCenter;
namespace web
{

    public class AdminController : Controller
    {
        #region 私有变量
        private User _user;
        #endregion

        #region 当前用户
        public User CurrentUser
        {
            get
            {
                if (_user == null)
                {
                    _user = User.ReadFirst("LoginID=@LoginID", "@LoginId", Session["User"].ToString());
                }
                return _user;
            }
            set { CurrentUser = value; }
        }
        #endregion

        [BeforeAction]
        public void BeforeAction()
        {
            #region 加载模板
            this.ChangeLayout("Master/AdminMaster");
            #endregion

            if (Session["User"] == null)
            {
                if (Request["toKen"] != null)
                {

                    SSOtest.ServiceCenter.ServiceCenterSoapClient sc = new ServiceCenterSoapClient();
                    string userId = sc.CheckToken(Request["toKen"].ToString(), HttpContext.Current.Request.UserHostAddress);
                    if (!string.IsNullOrEmpty(userId))
                    {
                        Session["User"] = userId;
                        Session["toKen"] = Request["toKen"].ToString();
                        Redirect("~/admin/default");
                    }
                }
                Redirect("~/admin/login");
                return;
            }
        }
    }
}